package com.tigger.core.redisson.lock;

import com.tigger.core.redisson.DistributedRReadWriteLocker;
import org.redisson.api.RLock;

import java.util.concurrent.TimeUnit;

/**
 * Created by root on 2018/7/22.
 */
public class RedissonRRWLock {

    private static DistributedRReadWriteLocker distributedRReadWriteLocker;

    public static void setLocker(DistributedRReadWriteLocker locker) {
        distributedRReadWriteLocker = locker;
    }

    public static boolean readLock(String lockKey) {
        return distributedRReadWriteLocker.readLock(lockKey);
    }

    public static boolean writeLock(String lockKey) {
        return distributedRReadWriteLocker.writeLock(lockKey);
    }

    public static boolean readLock(String lockKey, TimeUnit unit, int timeout) {
        return distributedRReadWriteLocker.readLock(lockKey, unit, timeout);
    }

    public static boolean writeLock(String lockKey, TimeUnit unit, int timeout) {
        return distributedRReadWriteLocker.writeLock(lockKey, unit, timeout);
    }

    public static boolean tryReadLock(String lockKey, TimeUnit unit, int waitTime, int leaseTime) {
        return distributedRReadWriteLocker.tryReadLock(lockKey, unit, waitTime, leaseTime);
    }

    public static boolean tryWriteLock(String lockKey, TimeUnit unit, int waitTime, int leaseTime) {
        return distributedRReadWriteLocker.tryWriteLock(lockKey, unit, waitTime, leaseTime);
    }

    public static void unlock(RLock lock) {
        distributedRReadWriteLocker.unlock(lock);
    }

    public static void releaseReadLock(String lockKey) {
        distributedRReadWriteLocker.releaseReadLock(lockKey);
    }

    public static void releaseWriteLock(String lockKey) {
        distributedRReadWriteLocker.releaseWriteLock(lockKey);
    }
}
